﻿using ImageControl.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ImageControl
{
    /// <summary>
    /// Interaction logic for ImagesControl.xaml
    /// </summary>
    public partial class ImagesControl : UserControl
    {
        private readonly ApplicationViewModel appViewModel;

        public ImagesControl()
        {
            InitializeComponent();
            this.appViewModel = this.presenter.DataContext as ApplicationViewModel;    
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.CaptureMouse();
            this.appViewModel.RegisterMouseDown(this.GetDocumentPoint(e));
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.ReleaseMouseCapture();
            this.appViewModel.RegisterMouseUp(this.GetDocumentPoint(e));
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            this.appViewModel.RegisterMouseMove(this.GetDocumentPoint(e));            
        }

        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            this.appViewModel.RegisterMouseLeave(this.GetDocumentPoint(e));
        }

        private Point GetDocumentPoint(MouseEventArgs e)
        {
            return e.GetPosition(this.presenter);
        }
    }
}
